/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;

/**
 *
 * @author joseph
 */
public class DateUtil {
    
    public static final String DATE_FORMAT_NOW = "yyyy-MM-dd";
    
    public static int maxDays(int month, int year) {
        if (year == 0) {
            year = 2013;
        }
        Calendar c = GregorianCalendar.getInstance();
        c.set(year, month - 1, 1, 0, 0);
        int maxDays = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        return maxDays;
    }
    
    public static boolean leapYear(int year) {
        GregorianCalendar c = new GregorianCalendar();
        return c.isLeapYear(year);
    }
    
    public static String currentDate() {
        Calendar c = GregorianCalendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        return sdf.format(c.getTime());
    }
    
    public static int getDayOfTheWeek(int year, int month, int day) {
        Calendar c = GregorianCalendar.getInstance();
        c.set(year, month - 1, day, 0, 0);
        int day_of_week = c.get(Calendar.DAY_OF_WEEK);
        return day_of_week;
    }
    
    public static String getDayNameFromCal(int year, int month, int day) {
        Calendar c = GregorianCalendar.getInstance();
        c.set(year, month - 1, day, 0, 0);
        String dayName = c.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, new Locale("da"));
        return dayName.substring(0, 1).toUpperCase() + dayName.substring(1);
    }
    
    public static String getDayNameFromString(String day) {
        String str;
        switch (day) {
            case "Monday":
                str = "Mandag";
                break;
            case "Tuesday":
                str = "Tirsdag";
                break;
            case "Wednesday":
                str = "Onsdag";
                break;
            case "Thursday":
                str = "Torsdag";
                break;
            case "Friday":
                str = "Fredag";
                break;
            case "Saturday":
                str = "Lørdag";
                break;
            case "Sunday":
                str = "Søndag";
                break;
            default:
                str = "Ukendt dag";
        }
        return str;
    }
}
